//
//  ByBasketBallSFCell.m
//  caipiao_ios
//
//  Created by mc on 2018/9/6.
//  Copyright © 2018年 ZhangZhanbin. All rights reserved.
//

#import "ByBasketBallSFCell.h"

@implementation ByBasketBallSFCell

+ (instancetype)cellWithTableView:(UITableView*)tableView{
    
    static NSString *cellIdentifier = @"ByBasketBallSFCell";
    ByBasketBallSFCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[self alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    return cell;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSeparatorStyleNone;
        self.contentView.backgroundColor = BY_BACKGROUND_COLOR;
        
        [self initViews];
    }
    return self;
}


- (void)initViews{
    
    [self.contentView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    
    UIView *backgroundView = [[UIView alloc] init];
    backgroundView.layer.cornerRadius = 10;
    backgroundView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:backgroundView];
    [backgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(0);
        make.left.equalTo(self.contentView).offset(5);
        make.right.equalTo(self.contentView).offset(-5);
        make.bottom.equalTo(self.contentView).offset(-10);
    }];
    
    
    ByFootBallTitleView *titleView = [[ByFootBallTitleView alloc] init];
    [backgroundView addSubview:titleView];
    [titleView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(backgroundView).offset(0);
        make.right.equalTo(backgroundView).offset(0);
        make.top.equalTo(backgroundView).offset(0);
        make.height.mas_equalTo(@85);
    }];
    self.titleView = titleView;
    
    UILabel *vsLabel = [[UILabel alloc] init];
    [backgroundView addSubview:vsLabel];
    [vsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(backgroundView).offset(0);
        make.top.equalTo(backgroundView).offset(100);
        make.size.mas_equalTo(CGSizeMake(50, 20));
    }];
    vsLabel.text = @"vs";
    vsLabel.textColor = [UIColor blackColor];
    vsLabel.textAlignment = NSTextAlignmentCenter;
    vsLabel.font = FONT(14);
    self.vsLabel = vsLabel;
    
    
    UIButton *leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [backgroundView addSubview:leftBtn];
    [leftBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(backgroundView).offset(35);
        make.centerY.equalTo(vsLabel.mas_centerY).offset(0);
        make.right.equalTo(vsLabel.mas_left).offset(0);
        make.height.mas_equalTo(@45);
    }];
    leftBtn.backgroundColor = BY_THEME_COLOR;
    leftBtn.tag = 100;
    [leftBtn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
    self.leftBtn = leftBtn;
    
    UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [backgroundView addSubview:rightBtn];
    [rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(backgroundView).offset(-35);
        make.centerY.equalTo(vsLabel.mas_centerY).offset(0);
        make.left.equalTo(vsLabel.mas_right).offset(0);
        make.height.mas_equalTo(@45);
    }];
    rightBtn.layer.borderColor = BY_LINE_COLOR.CGColor;
    rightBtn.layer.borderWidth = 1;
    rightBtn.tag = 200;
    [rightBtn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
    self.rightBtn = rightBtn;
}


- (void)setDataArray:(NSMutableArray *)dataArray{
    
    _dataArray = dataArray;
    
    ByNetModel *model = [_dataArray firstObject];
    self.titleView.isBasketBall = YES;
    self.titleView.netModel = model;
    self.titleView.danguanView.hidden = model.single.integerValue == 0;
    
    ByNetModel *fistModel = [dataArray firstObject];
    ByNetModel *lastModel = [dataArray lastObject];
    [self.leftBtn setTitle:[NSString stringWithFormat:@"%@ %@", fistModel .title,fistModel .valueString] forState:UIControlStateNormal];
    if (fistModel.selected) {
        self.leftBtn.backgroundColor = BY_THEME_COLOR;
        [self.leftBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    }else{
        
        self.leftBtn.backgroundColor = [UIColor whiteColor];
        [self.leftBtn setTitleColor:[UIColor  lightGrayColor] forState:UIControlStateNormal];
        self.leftBtn.layer.borderColor = BY_LINE_COLOR.CGColor;
        self.leftBtn.layer.borderWidth = 1;
    }
     [self.rightBtn setTitle:[NSString stringWithFormat:@"%@ %@", lastModel .title,lastModel .valueString] forState:UIControlStateNormal];
    
    if (lastModel.selected) {
        self.rightBtn.backgroundColor = BY_THEME_COLOR;
        [self.rightBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    }else{
        
        self.rightBtn.backgroundColor = [UIColor whiteColor];
        [self.rightBtn setTitleColor:[UIColor  lightGrayColor] forState:UIControlStateNormal];
        self.rightBtn.layer.borderColor = BY_LINE_COLOR.CGColor;
        self.leftBtn.layer.borderWidth = 1;
    }
    
    
        if (fistModel.isNoSale) {
            [self.leftBtn setTitle:@"未开售" forState:UIControlStateNormal];
            self.leftBtn.userInteractionEnabled = NO;
        }
    
}

- (void)btnAction:(UIButton *)btn{
    if (btn.tag == 100) {
        if (self.indexAtView) {
            self.indexAtView(0);
        }
    }else{
        if (self.indexAtView) {
            self.indexAtView(1);
        }
    }
}

@end
